package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.activity.client.ActivityFeignClient;
import com.atguigu.gmall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * title:
 * author: Gyh
 * date:2023-05-14 16:45
 * Description:
 */
@Controller
public class ActivityController {

    @Autowired
    private ActivityFeignClient activityFeignClient;

    /**
     * 秒杀页面渲染
     * @param model
     * @return
     */
    @GetMapping("/seckill.html")
    public String seckillHtml(Model model){
        Result result = activityFeignClient.getSeckillGoodsList();
        model.addAttribute("list",result.getData());
        return "/seckill/index";
    }

    /**
     * 秒杀商品详情页渲染
     * @param model
     * @param skuId
     * @return
     */
    @GetMapping("/seckill/{skuId}.html")
    public String seckillGoodsItemHtml(Model model, @PathVariable("skuId") Long skuId){
        Result result = activityFeignClient.getSeckillGoods(skuId);
        model.addAttribute("item",result.getData());
        return "/seckill/item";
    }
}
